<template>
	<view>
		<u-navbar :border-bottom='false' back-icon-size='48' title="添加好友"></u-navbar>
		<view class="container">
			<view class="select-box" @click="showPicker=true">
				<view class="text">
					{{choseText}}
				</view>
				<u-icon name="arrow-down" color="#666666" size="28"></u-icon>
			</view>

			<view class="content" v-if="inviteList.length">
				<view class="cell-ul">
					<view class="cell-li" v-for="(item,index) in inviteList" :key='index'>
						<view class="left">
							<image class="headPic" :src="item.head_pic" mode=""></image>
							<view class="info">
								<view class="name">
									<text>{{item.nickname}}</text>
								</view>
								<view class="num">
									ID：{{item.user_id}}
								</view>
							</view>
						</view>
						<view class="add" @click="handleClick(item.chat_user_id)">
							<u-icon name="plus-circle" color="#666666" size="40"></u-icon>
						</view>
					</view>
				</view>
			</view>
			<view class="noCont" v-else>
				<u-empty text="暂无可添加好友" mode="list"></u-empty>
			</view>

		</view>

		<u-picker mode="selector" v-model="showPicker" :default-selector="[0]" :range="selector" @confirm="confirm">
		</u-picker>
	</view>
</template>

<script>
	import myRequest from '@/api/index.js'
	import _get from '@/common/_get';
	import _hook from '@/common/_hook';
	import _data from '@/common/_data';
	export default {
		data() {
			return {
				showPicker: false,
				choseText: '会员',
				selector: ['会员', 'VIP', '合伙人'],
				inviteList: [],
				page: '1',
				type: 0,
				is_type: 0,
				is_in: 0,
			}
		},
		onLoad() {
			this.getPromote()
		},
		onReachBottom() {
			let page = Number(this.page) + 1
			this.page = page.toString()
			this.getPromote()
		},
		methods: {
			// 添加好友
			handleClick(id) {
				uni.navigateTo({
					url: ('../details/index?user_id=' + id + '&is_type=' + this.is_type),
				})
			},
			// 获取推广人数
			async getPromote() {
				let {
					page,
					type
				} = this
				let res = await myRequest.getMyinvite({
					page: page,
					type: type.toString()
				})
				if (res.status) {
					this.inviteList = [...this.inviteList, ...res.data]
				}
			},
			confirm(val) {
				let index = val[0]
				this.choseText = this.selector[index]
				this.page = '1'
				this.inviteList = []
				if (index == 0) {
					this.type = 0
				}
				if (index == 1) {
					this.type = 1
				}
				if (index == 2) {
					this.type = 4
				}
				this.getPromote()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		.select-box {
			width: 100%;
			height: 100rpx;
			display: flex;
			align-items: center;
			padding-left: 40rpx;

			.text {
				margin-right: 8rpx;
			}
		}

		.content {
			width: 100%;
			height: auto;
			padding: 0 20rpx;
			background-color: #FFFFFF;

			.cell-ul {
				width: 100%;
				height: auto;

				.cell-li {
					width: 100%;
					height: 140rpx;
					border-bottom: 2rpx solid #F2F2F2;
					display: flex;
					align-items: center;

					&:last-child {
						border-bottom: none;
					}

					.left {
						display: flex;
						align-items: center;

						.headPic {
							width: 72rpx;
							height: 72rpx;
							border-radius: 50%;
						}

						.info {
							margin-left: 30rpx;

							.name {
								font-size: 32rpx;
								font-family: PingFang SC;
								font-weight: 400;
								color: #333333;
								display: flex;
								align-items: center;

								.tjian {
									width: 108rpx;
									height: 46rpx;
									background: #E7F3FF;
									border-radius: 40rpx;
									font-size: 24rpx;
									font-family: PingFang SC;
									font-weight: 400;
									line-height: 46rpx;
									color: #3587F7;
									text-align: center;
									margin-left: 34rpx;
								}

							}

							.num {
								margin-top: 8rpx;
								font-size: 28rpx;
								font-family: Segoe UI;
								font-weight: 400;
								color: #666666;
							}
						}
					}

					.add {
						margin-left: auto;
					}
				}
			}
		}
	}

	.noCont {
		padding-top: 320rpx;
	}
</style>
